﻿using System;
using System.Windows;
using System.Windows.Input;
using DataBaseLibrary.DBObjectsFB;

namespace DocMreoLiteVersion
{
    /// <summary>
    /// Interaction logic for IndividualInputData.xaml
    /// </summary>
    public partial class IndividualInputData : Window
    {
        private Individual individual = null;

        public IndividualInputData()
        {
            InitializeComponent();
        }

        public IndividualInputData(Individual individual)
            : this()
        {
            this.individual = individual;
            DataContext = individual;
        }

        private void TextBox_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                const FocusNavigationDirection focusNav = FocusNavigationDirection.Next;
                var request = new TraversalRequest(focusNav);

                if ((sender as UIElement) != null)
                    (sender as UIElement).MoveFocus(request);

               e.Handled = true;
            }

        }

        private void OkClick(object sender, RoutedEventArgs e)
        {
            if (individual == null)
                individual = new Individual();


            if (individual.LastName == String.Empty && individual.FirstName == String.Empty &&
                individual.Patronymic == String.Empty && individual.PassportNumber == String.Empty &&
                individual.PassportSeries == String.Empty)
            {
                MessageBox.Show("Заполните хотябы одно поле!");
                return;
            }

            DialogResult = true;
        }

        private void CloseClick(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
        }
    }
}
